package com.suwish.pc.ui.dialog;

import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Window;
import java.awt.event.ActionEvent;
import java.util.Map;

import javax.swing.AbstractAction;
import javax.swing.DefaultListModel;
import javax.swing.JButton;
import javax.swing.JList;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.table.DefaultTableModel;

import com.android.ddmlib.IDevice;
import com.suwish.pc.ui.component.KeyValueItem;
import com.suwish.pc.ui.component.UIDialog;

/**
 * 
 * @author Min
 *
 */
public class DevicePropDialog extends UIDialog {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	
	private DefaultTableModel tableMode = null;
	private JTable table = null;
	private JButton submitButton = null;
	private JButton cancelButton = null;
	
	private IDevice device = null;
	
	public DevicePropDialog(Window parent, IDevice device){		
		super(parent, "Device Property");
		this.device = device;
		setModal(true);
		
		initUI();
		initData();
		
		setSize(new Dimension(560, 420));
		setLocationRelativeTo(parent);
		
	}
	private void initData(){
		Map<String, String> prop = device.getProperties();
		for(String key : prop.keySet()){
			tableMode.addRow(new Object[]{key , prop.get(key)});
		}
	}
	private void initUI(){
		table = new JTable(tableMode = new DefaultTableModel());
		tableMode.addColumn("KEY");
		tableMode.addColumn("VALUE");
//		table.setE
		getIContentPane().setLayout(new BorderLayout());
		getIContentPane().add(new JScrollPane(table), BorderLayout.CENTER);
		JPanel buttomPane = new JPanel(new FlowLayout(FlowLayout.CENTER));
		getIContentPane().add(buttomPane, BorderLayout.SOUTH);
		   
//	   submitButton = new JButton("Submit");
	   cancelButton = new JButton("Cancle");
//	   submitButton.addActionListener(new AbstractAction() {	
//		private static final long serialVersionUID = 1L;
//		@Override
//		public void actionPerformed(ActionEvent e) {
//			int index = deviceList.getSelectedIndex();
//			if(index < 0) return;
//			KeyValueItem item = (KeyValueItem)listModel.get(index);
//			device = (IDevice)item.getValue();
//			dispose();
//		}
//	   });
	   cancelButton.addActionListener(new AbstractAction() {	
			private static final long serialVersionUID = 1L;
			@Override
			public void actionPerformed(ActionEvent e) {
				dispose();
			}
		   });
//	   buttomPane.add(submitButton);
	   buttomPane.add(cancelButton);
	}
}
